package cn.stylefeng.guns.modular.lx.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.lx.entity.LxSpZw;
import cn.stylefeng.guns.modular.lx.mapper.LxSpWzhMapper;
import cn.stylefeng.guns.modular.lx.mapper.LxSpZwMapper;
import cn.stylefeng.guns.modular.lx.mapper.LxSplbZwMapper;
import cn.stylefeng.guns.modular.lx.model.params.LxDdZwParam;
import cn.stylefeng.guns.modular.lx.model.params.LxSpZwParam;
import cn.stylefeng.guns.modular.lx.model.result.LxSpZwResult;
import  cn.stylefeng.guns.modular.lx.service.LxSpZwService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zw
 * @since 2023-12-01
 */
@Service
public class LxSpZwServiceImpl extends ServiceImpl<LxSpZwMapper, LxSpZw> implements LxSpZwService {

    @Autowired
    private LxSpZwMapper lxSpZwMapper;
    @Override
    public void add(LxSpZwParam param) {
        LxSpZw entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(LxSpZwParam param) {
        this.removeById(getKey(param));
    }

    @Override
    public void update(LxSpZwParam param) {
        LxSpZw oldEntity = getOldEntity(param);
        LxSpZw newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public LxSpZwResult findBySpec(LxSpZwParam param) {
        return null;
    }

    @Override
    public List<LxSpZwResult> findListBySpec(LxSpZwParam param) {
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(LxSpZwParam param, String condition) {
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param, condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(LxSpZwParam param) {
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private LxSpZw getOldEntity(LxSpZwParam param) {
        return this.getById(getKey(param));
    }

    @Override
    public void reducechl(int id, int buyNum) {
        this.baseMapper.reducechl(id, buyNum);
    }

    private LxSpZw getEntity(LxSpZwParam param) {
        LxSpZw entity = new LxSpZw();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }


}
